{% extends 'admin/indexBase.html' %}

{% block title %}图书管理{% endblock %}

{% block search %}
    <form class="navbar-form navbar-right" method="get" action="{{ url_for('bookAdmin.search_book') }}">
        <input type="text" class="form-control" name="kw" placeholder="Search...Books">
        <input type="hidden" name="page" value="0">
        <input type="submit" class="form-control" value="搜索">
    </form>
{% endblock %}

{% block main %}
    <h2 class="sub-header">图书列表</h2>
    <div class="table-responsive">
        <table class="table table-striped">
            <thead class="row">
            <tr>
                <th class="col-1">#</th>
                <th class="col-1">书名</th>
                <th class="col-1">作者</th>
                <th class="col-lg-5">简介</th>
                <th class="col-1">价格</th>
                <th class="col-md-2"></th>
            </tr>
            </thead>
            <tbody>
            {% for book in books %}
                <tr>
                    <td>{{ loop.index }}</td>
                    <td>{{ book.title }}</td>
                    <td>{{ book.author }}</td>
                    <td>{{ book.subheading }}</td>
                    <td>{{ book.price }}</td>
                    <td><a type="button" class="btn btn-primary" role="button"
                           href="{{ url_for('bookAdmin.bookDetails' , book_id=book['_id']) }}">详情</a>
                        <a type="button" class="btn btn-primary" role="button"
                           href="{{ url_for('bookAdmin.off_shelf' , book_id=book['_id']) }}"
                           onclick="javascrip:return confirm('您确定要将该物品下架？')">下架</a>
                    </td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
    </div>
    <div id="pages" data-tap-disabled="true">
    </div>

    <script>
        new Pagination({
            element: '#pages',
            type: 1,
            pageIndex: {{ active_page }},   //默认活动页
            pageSize: {{ page_size }},	//一页数量
            pageCount: {{ page_count }},   //显示页数
            total: {{ total }},      //总数
            jumper: true,
            singlePageHide: true,
            prevText: '上一页',
            nextText: '下一页',
            disabled: false,
            currentChange: function (index) {
                {#console.log(index);#}
                //https://blog.csdn.net/pengShuai007/article/details/86528992
                var a = document.createElement('a');
                a.setAttribute('href', '/admin/bookAdmin?page='+index);
                a.setAttribute('id', 'startTelMedicine');
                // 防止反复添加
                if (document.getElementById('startTelMedicine')) {
                    document.body.removeChild(document.getElementById('startTelMedicine'));
                }
                document.body.appendChild(a);
                a.click();
            }
        });
    </script>
{% endblock %}

